package com.marsoft.test.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marsoft.test.entity.CollateralMessageDetailEntity;
import com.marsoft.test.entity.WarehouseApplyEntity;
import com.marsoft.test.mapper.WarehouseApplyMapper;
import com.marsoft.test.service.WarehouseApplyService;
import com.marsoft.test.utils.RandomNumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class WarehouseApplyServiceImpl implements WarehouseApplyService {
    @Autowired
    private WarehouseApplyMapper warehouseApplyMapper;
    @Override
    public List<WarehouseApplyEntity> findByApplyNoStatus(Integer warehouseApplyStatus, String warehouseApplyNo, Integer page, Integer pageSize) {
        WarehouseApplyEntity warehouseApplyEntity = new WarehouseApplyEntity();
        //分页起始码以及每页页数
        PageHelper.startPage(page,pageSize);
        List<WarehouseApplyEntity> byApplyNoStatus = warehouseApplyMapper.findByApplyNoStatus(warehouseApplyStatus,warehouseApplyNo);
        PageInfo pageInfo = new PageInfo(byApplyNoStatus);
        return pageInfo.getList();
    }

    @Override
    public void insertwarehouseApply(WarehouseApplyEntity warehouseApplyEntity) {
        WarehouseApplyEntity warehouseApplyEntity1 = new WarehouseApplyEntity();
        String s = RandomNumberUtils.randomNumber();
        warehouseApplyEntity1.setCollateralNo(s);
        warehouseApplyEntity1.setWarehouseApplyStatus(warehouseApplyEntity.getWarehouseApplyStatus());
        warehouseApplyEntity1.setWarehouseApplyNo(s);
        warehouseApplyEntity1.setCurrentProcess(warehouseApplyEntity.getCurrentProcess());
        warehouseApplyEntity1.setCurrentGeneration(warehouseApplyEntity.getCurrentGeneration());
        warehouseApplyEntity1.setConfirmValue(warehouseApplyEntity.getConfirmValue());
        warehouseApplyEntity1.setCollateralName(warehouseApplyEntity.getCollateralName());
        warehouseApplyEntity1.setApplicationType(warehouseApplyEntity.getApplicationType());
        warehouseApplyEntity1.setApplicationName(warehouseApplyEntity.getApplicationName());
        warehouseApplyEntity1.setApplicationOrganization(warehouseApplyEntity.getApplicationOrganization());
        warehouseApplyMapper.insertwarehouseApply(warehouseApplyEntity1);
    }

    @Override
    public void updatewarehouseApply(WarehouseApplyEntity warehouseApplyEntity) {
        WarehouseApplyEntity warehouseApplyEntity1 = new WarehouseApplyEntity();
        warehouseApplyEntity1.setWarehouseApplyNo(warehouseApplyEntity.getWarehouseApplyNo());//入库申请申请编号
        warehouseApplyEntity1.setCollateralName(warehouseApplyEntity.getCollateralName());//押品名称
        warehouseApplyEntity1.setConfirmValue(warehouseApplyEntity.getConfirmValue());//确认价值
        warehouseApplyEntity1.setApplicationName(warehouseApplyEntity.getApplicationName());//申请人
        warehouseApplyEntity1.setApplicationOrganization(warehouseApplyEntity.getApplicationOrganization());//申请机构
        warehouseApplyMapper.updatewarehouseApply(warehouseApplyEntity1);
    }

    @Override
    public void deletewarehouseApply(String warehouseApplyNo) {
        WarehouseApplyEntity warehouseApplyEntity = new WarehouseApplyEntity();
        warehouseApplyEntity.setWarehouseApplyNo(warehouseApplyNo);
        warehouseApplyEntity.setLogicDelete("0");
        warehouseApplyMapper.deletewarehouseApply(warehouseApplyEntity);
    }

    @Override
    public List<CollateralMessageDetailEntity> findCollateralMessageDetail(String warehouseApplyNo,Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<CollateralMessageDetailEntity> collateralMessageDetail = warehouseApplyMapper.findCollateralMessageDetail(warehouseApplyNo);
        PageInfo pageInfo = new PageInfo<>(collateralMessageDetail);
        return pageInfo.getList();
    }
}
